/**
 * File Name   : LoginForm.java
 * Description : 
 */
package com.hh.admin.login.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.hh.common.util.StringUtil;


/**
 * @author 冯昌硕
 * @create 2012-12-6 下午8:43:06
 */
public class LoginForm extends ActionForm {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -7231754766597794679L;
    
    private static final Logger log = Logger.getLogger(LoginForm.class);

    /**
     * 用户名
     */
    private String account;

    /**
     * 密码
     */
    private String password;
    
    /**
     * Form表单校验
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        
        if (StringUtil.isEmpty(this.account)) {
            ActionMessage errorMsg = new ActionMessage("login.error.username.mustinput");
            errors.add("username.mustinput", errorMsg);
            log.info("后台登录:用户名不能为空");
        } else {
            this.account = this.account.trim();
            
            if (StringUtil.isNotUsername(this.account)) {
                ActionMessage errorMsg = new ActionMessage("login.error.username.word");
                errors.add("username.word", errorMsg);
                
                log.info("后台登录:用户名格式不正确");
            }
        }
        
        if (StringUtil.isEmpty(this.password)) {
            ActionMessage errorMsg = new ActionMessage("login.error.password.null");
            errors.add("password.null", errorMsg);

            log.info("后台登录:密码不能为空");
        } else {
            this.password = this.password.trim();
        }
        
        return errors;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
